/*	Brian Kirkpatrick
	QuX class
	Begun 6/30/2010

	Queried XML management for low-level languages
*/

#ifndef QUX_CLASS_H
#define QUX_CLASS_H

#include <stdio.h>
#include "stringTree.h"
#include "quxResult.h"

using std::ifstream;

class QuX {
private:
	stringTree * data;
	string filename;
	string error;

	// Private method used for recursive xml parsing
	bool parse(FILE * file, stringTree * parent, int level, TreeType state, char carryover=' ');

	// Relevant string operations
	bool isWhitespace(char c);
	string trimStr(string s);
	string lowerStr(string s);
	int search(string needle, string haystack);
	string intToStr(int n);
	stringDict explodeStr(string s, string d, bool t=false);

	// Operation-specific query methods and support
	quxResult selectQuery(string q);
	quxResult insertQuery(string q);
	quxResult updateQuery(string q);
	quxResult select(stringTree * node, stringDict fields, stringDict sources);
	string getValue(stringTree * node, string aettribute);
protected:
public:
	// Constructors
	QuX();
	~QuX();

	// Accessors
	string getError();

	// Methods
	bool open(string f);
	bool write(string f="");
	quxResult query(string qry);
	void print();
};

#endif